ARD2  RC2
Airbag Reference Demonstrator using MPC5604P
freemaster_rec.c
Go to the documentation of this file.
00001 /******************************************************************************
00002 *
00003 * Freescale Semiconductor Inc.
00004 * (c) Copyright 2004-2011 Freescale Semiconductor
00005 * ALL RIGHTS RESERVED.
00006 *
00007 ****************************************************************************/
00019 #include "freemaster.h"
00020 #include "freemaster_private.h"
00021 #include "freemaster_protocol.h"
00022 
00023 #if FMSTR_USE_RECORDER && (!FMSTR_DISABLE)
00024 
00025 #include "freemaster_rec.h"
00026 
00027 #if FMSTR_USE_FASTREC
00028 #include "freemaster_fastrec.h"
00029 #endif
00030 
00031 /********************************************************
00032 *  global variables (shared with FastRecorder if used)
00033 ********************************************************/
00034 
00035 /* configuration variables */
00036 FMSTR_U16  pcm_wRecTotalSmps;        /* number of samples to measure */
00037 
00038 #if FMSTR_REC_STATIC_POSTTRIG == 0
00039 FMSTR_U16  pcm_wRecPostTrigger;      /* number of post-trigger samples to keep */
00040 #endif
00041 
00042 #if (FMSTR_USE_FASTREC) == 0
00043 FMSTR_U8   pcm_nRecTriggerMode;      /* trigger mode (0 = disabled, 1 = _/, 2 = \_) */
00044 #endif
00045 
00046 #if (FMSTR_REC_STATIC_DIVISOR) == 0
00047 FMSTR_U16  pcm_wRecTimeDiv;          /* divisor of recorder "clock" */
00048 #endif
00049 
00050 FMSTR_U8    pcm_nRecVarCount;        /* number of active recorder variables */
00051 FMSTR_ADDR  pcm_pRecVarAddr[FMSTR_MAX_SCOPE_VARS]; /* addresses of recorded variables */
00052 FMSTR_SIZE8 pcm_pRecVarSize[FMSTR_MAX_SCOPE_VARS]; /* sizes of recorded variables */
00053 
00054 /* runtime variables  */
00055 #if (FMSTR_REC_STATIC_DIVISOR) != 1
00056 FMSTR_U16  pcm_wRecTimeDivCtr;       /* recorder "clock" divisor counter */
00057 #endif
00058 
00059 FMSTR_U16  pcm_wStoprecCountDown;    /* post-trigger countdown counter */
00060 
00061 /* recorder flags */
00062 FMSTR_REC_FLAGS pcm_wRecFlags;
00063 
00064 /***********************************
00065 *  local variables 
00066 ***********************************/
00067 
00068 #if (FMSTR_USE_FASTREC) == 0
00069 FMSTR_U16   pcm_wRecBuffStartIx;     /* first sample index */
00070 
00071 /* Recorder buffer pointers */
00072 FMSTR_ADDR pcm_dwRecWritePtr;        /* write pointer in recorder buffer */
00073 FMSTR_ADDR pcm_dwRecEndBuffPtr;      /* pointer to end of active recorder buffer */
00074 
00075 /* configuration variables */
00076 static FMSTR_ADDR pcm_nTrgVarAddr;          /* trigger variable address */
00077 static FMSTR_U8   pcm_nTrgVarSize;          /* trigger variable threshold size */
00078 static FMSTR_U8   pcm_bTrgVarSigned;        /* trigger compare mode (0 = unsigned, 1 = signed) */
00079 
00080 /*lint -e{960} using union */
00081 static union 
00082 {
00083 #if FMSTR_CFG_BUS_WIDTH == 1
00084     FMSTR_U8  u8; 
00085     FMSTR_S8  s8;
00086 #endif
00087     FMSTR_U16 u16;
00088     FMSTR_S16 s16;
00089     FMSTR_U32 u32;
00090     FMSTR_S32 s32;
00091 #if FMSTR_REC_FLOAT_TRIG
00092     FMSTR_FLOAT fp;
00093 #endif
00094 } pcm_uTrgThreshold;                        /* trigger threshold level (1,2 or 4 bytes) */
00095 #endif /* (FMSTR_USE_FASTREC) == 0 */
00096 
00097 static FMSTR_ADDR  pcm_nRecBuffAddr;        /* recorder buffer address */
00098 #if FMSTR_REC_OWNBUFF
00099 static FMSTR_SIZE  pcm_wRecBuffSize;        /* recorder buffer size */
00100 #endif
00101 /* compare functions prototype */
00102 typedef FMSTR_BOOL (*FMSTR_PCOMPAREFUNC)(void);
00103 
00104 /*/ pointer to active compare function */
00105 static FMSTR_PCOMPAREFUNC pcm_pCompareFunc;
00106 
00107 #if !FMSTR_REC_OWNBUFF && (FMSTR_USE_FASTREC) == 0
00108 /* put buffer into far memory ? */
00109 #if FMSTR_REC_FARBUFF
00110 #pragma section fardata begin
00111 #endif /* FMSTR_REC_FARBUFF */
00112 /* statically allocated recorder buffer (FMSTR_REC_OWNBUFF is FALSE) */
00113 static FMSTR_U8 pcm_pOwnRecBuffer[FMSTR_REC_BUFF_SIZE];
00114 /* end of far memory section */
00115 #if FMSTR_REC_FARBUFF
00116 #pragma section fardata end
00117 #endif /* FMSTR_REC_FARBUFF */
00118 #endif /* FMSTR_REC_OWNBUFF */
00119 
00120 /***********************************
00121 *  local functions
00122 ***********************************/
00123 
00124 static FMSTR_BOOL FMSTR_Compare8S(void);
00125 static FMSTR_BOOL FMSTR_Compare8U(void);
00126 static FMSTR_BOOL FMSTR_Compare16S(void);
00127 static FMSTR_BOOL FMSTR_Compare16U(void);
00128 static FMSTR_BOOL FMSTR_Compare32S(void);
00129 static FMSTR_BOOL FMSTR_Compare32U(void);
00130 #if FMSTR_REC_FLOAT_TRIG
00131 static FMSTR_BOOL FMSTR_Comparefloat(void);
00132 #endif
00133 static void FMSTR_Recorder2(void);
00134 
00135 /**************************************************************************/
00141 void FMSTR_InitRec(void)
00142 {   
00143     /* initialize Recorder flags*/
00144     pcm_wRecFlags.all = 0U;
00145 
00146     /* setup buffer pointer and size so IsInRecBuffer works even  
00147        before the recorder is first initialized and used */
00148     
00149 #if FMSTR_REC_OWNBUFF
00150     /* user wants to use his own buffer */
00151     pcm_nRecBuffAddr = 0U;
00152     pcm_wRecBuffSize = 0U;
00153 #elif FMSTR_USE_FASTREC
00154     /* Initialize Fast Recorder Buffer  */
00155     FMSTR_InitFastRec();
00156 #else
00157     /* size in native sizeof units (=bytes on most platforms) */
00158     FMSTR_ARR2ADDR(pcm_nRecBuffAddr, pcm_pOwnRecBuffer);
00159     
00160     /*lint -esym(528, pcm_pOwnRecBuffer) this symbol is used outside of lint sight */
00161 #endif
00162 
00163 }
00164 
00165 /**************************************************************************/
00171 #if defined(FMSTR_PLATFORM_HC08) || defined(FMSTR_PLATFORM_HC12)
00172 #pragma INLINE
00173 #else 
00174 inline
00175 #endif
00176 void FMSTR_AbortRec(void)
00177 {
00178     /* clear flags */
00179     pcm_wRecFlags.all = 0U;
00180 }
00181 
00182 /**************************************************************************/
00193 void FMSTR_SetUpRecBuff(FMSTR_ADDR pBuffer, FMSTR_SIZE nBuffSize)
00194 {    
00195 #if FMSTR_REC_OWNBUFF
00196     pcm_nRecBuffAddr = pBuffer;
00197     pcm_wRecBuffSize = nBuffSize;
00198 #else
00199     FMSTR_UNUSED(pBuffer);
00200     FMSTR_UNUSED(nBuffSize);    
00201 #endif
00202 }
00203 
00204 /**************************************************************************/
00215 FMSTR_BPTR FMSTR_SetUpRec(FMSTR_BPTR pMessageIO)
00216 {
00217     FMSTR_BPTR pResponse = pMessageIO;
00218     FMSTR_SIZE8 nRecVarsetSize;
00219     FMSTR_SIZE blen;
00220     FMSTR_U8 i, sz;
00221     FMSTR_U8 nResponseCode;
00222     
00223     /* de-initialize first   */
00224     FMSTR_AbortRec();
00225 
00226 #if FMSTR_REC_OWNBUFF
00227     /* user wants to use his own buffer, check if it is valid */
00228     if(!pcm_nRecBuffAddr || !pcm_wRecBuffSize)
00229     {
00230         return FMSTR_ConstToBuffer8(pResponse, FMSTR_STC_INVBUFF);
00231     }
00232 #elif (FMSTR_USE_FASTREC) == 0
00233     /* size in native sizeof units (=bytes on most platforms) */
00234     FMSTR_ARR2ADDR(pcm_nRecBuffAddr, pcm_pOwnRecBuffer);
00235 #endif
00236 
00237     /* seek the setup data */
00238 #if (FMSTR_USE_FASTREC) == 0
00239     pMessageIO = FMSTR_SkipInBuffer(pMessageIO, 2U);
00240     pMessageIO = FMSTR_ValueFromBuffer8(&pcm_nRecTriggerMode, pMessageIO);
00241 #else /* (FMSTR_USE_FASTREC) == 0 */
00242     pMessageIO = FMSTR_SkipInBuffer(pMessageIO, 3U);
00243 #endif /* (FMSTR_USE_FASTREC) == 0 */
00244 
00245     pMessageIO = FMSTR_ValueFromBuffer16(&pcm_wRecTotalSmps, pMessageIO);
00246 
00247 #if (FMSTR_REC_STATIC_POSTTRIG) == 0
00248     pMessageIO = FMSTR_ValueFromBuffer16(&pcm_wRecPostTrigger, pMessageIO);
00249 #else /* (FMSTR_REC_STATIC_POSTTRIG) == 0 */
00250     pMessageIO = FMSTR_SkipInBuffer(pMessageIO, 2U);
00251 #endif /* (FMSTR_REC_STATIC_POSTTRIG) == 0 */
00252 
00253 #if (FMSTR_REC_STATIC_DIVISOR) == 0
00254     pMessageIO = FMSTR_ValueFromBuffer16(&pcm_wRecTimeDiv, pMessageIO);
00255 #else /* (FMSTR_REC_STATIC_DIVISOR) == 0 */
00256     pMessageIO = FMSTR_SkipInBuffer(pMessageIO, 2U);
00257 #endif /* (FMSTR_REC_STATIC_DIVISOR) == 0 */
00258 
00259 #if (FMSTR_USE_FASTREC) == 0
00260     /* address & size of trigger variable */
00261     pMessageIO = FMSTR_AddressFromBuffer(&pcm_nTrgVarAddr, pMessageIO);
00262     pMessageIO = FMSTR_ValueFromBuffer8(&pcm_nTrgVarSize, pMessageIO);
00263 
00264     /* trigger compare mode  */
00265     pMessageIO = FMSTR_ValueFromBuffer8(&pcm_bTrgVarSigned, pMessageIO);
00266 
00267     /* threshold value  */
00268     pMessageIO = FMSTR_ValueFromBuffer32(&pcm_uTrgThreshold.u32, pMessageIO);
00269 #else /* (FMSTR_USE_FASTREC) == 0 */
00270     pMessageIO = FMSTR_SkipInBuffer(pMessageIO, 8U);
00271 #endif /* (FMSTR_USE_FASTREC) == 0 */
00272     
00273     /* recorder variable count */
00274     pMessageIO = FMSTR_ValueFromBuffer8(&pcm_nRecVarCount, pMessageIO);
00275 
00276     /* rec variable information must fit into our buffers */
00277     if(!pcm_nRecVarCount || pcm_nRecVarCount > (FMSTR_U8)FMSTR_MAX_REC_VARS)
00278     {
00279 #if FMSTR_REC_COMMON_ERR_CODES
00280         goto FMSTR_SetUpRec_exit_error;
00281 #else
00282         nResponseCode = FMSTR_STC_INVBUFF;
00283         goto FMSTR_SetUpRec_exit;
00284 #endif
00285     }
00286 
00287     /* calculate sum of sizes of all variables */
00288     nRecVarsetSize = 0U;
00289 
00290     /* get all addresses and sizes */
00291     for(i=0U; i<pcm_nRecVarCount; i++)
00292     {
00293         /* variable size */
00294         pMessageIO = FMSTR_ValueFromBuffer8(&sz, pMessageIO);
00295         
00296         pcm_pRecVarSize[i] = sz;
00297         nRecVarsetSize += sz;
00298         
00299         /* variable address */
00300         pMessageIO = FMSTR_AddressFromBuffer(&pcm_pRecVarAddr[i], pMessageIO);
00301 
00302         /* valid numeric variable sizes only */
00303         if(sz == 0U || sz > 8U)
00304         {
00305 #if FMSTR_REC_COMMON_ERR_CODES
00306             goto FMSTR_SetUpRec_exit_error;
00307 #else
00308             nResponseCode = FMSTR_STC_INVSIZE;
00309             goto FMSTR_SetUpRec_exit;
00310 #endif
00311         }
00312 
00313 #if FMSTR_CFG_BUS_WIDTH > 1U
00314         /* even sizes only */
00315         if(sz & 0x1)
00316         {
00317 #if FMSTR_REC_COMMON_ERR_CODES
00318             goto FMSTR_SetUpRec_exit_error;
00319 #else
00320             nResponseCode = FMSTR_STC_INVSIZE;
00321             goto FMSTR_SetUpRec_exit;
00322 #endif
00323         }
00324 #endif /* FMSTR_CFG_BUS_WIDTH > 1U */
00325         
00326 #if FMSTR_USE_TSA && FMSTR_USE_TSA_SAFETY
00327         if(!FMSTR_CheckTsaSpace(pcm_pRecVarAddr[i], (FMSTR_SIZE8)sz, 0U))
00328         {
00329 #if FMSTR_REC_COMMON_ERR_CODES
00330             goto FMSTR_SetUpRec_exit_error;
00331 #else
00332             nResponseCode = FMSTR_STC_EACCESS;
00333             goto FMSTR_SetUpRec_exit;
00334 #endif
00335         }
00336 #endif /* FMSTR_USE_TSA && FMSTR_USE_TSA_SAFETY */
00337     }
00338 
00339     /* fast recorder handles trigger by itself */
00340 #if (FMSTR_USE_FASTREC) == 0
00341     /* any trigger? */
00342     pcm_pCompareFunc = NULL;
00343     if(pcm_nRecTriggerMode)
00344     {
00345         /* access to trigger variable? */
00346 #if FMSTR_USE_TSA && FMSTR_USE_TSA_SAFETY
00347         if(!FMSTR_CheckTsaSpace(pcm_nTrgVarAddr, (FMSTR_SIZE8)pcm_nTrgVarSize, 0U))
00348         {
00349 #if FMSTR_REC_COMMON_ERR_CODES
00350             goto FMSTR_SetUpRec_exit_error;
00351 #else
00352             nResponseCode = FMSTR_STC_EACCESS;
00353             goto FMSTR_SetUpRec_exit;
00354 #endif
00355         }
00356 #endif /* FMSTR_USE_TSA && FMSTR_USE_TSA_SAFETY */
00357         /* get compare function */
00358 
00359 #if FMSTR_REC_FLOAT_TRIG
00360                 if(pcm_bTrgVarSigned&FMSTR_REC_FLOAT_TRIG_MASK)
00361                 {
00362                         pcm_pCompareFunc = FMSTR_Comparefloat;
00363                 }
00364                 else
00365 #else
00366                 if(pcm_bTrgVarSigned&FMSTR_REC_FLOAT_TRIG_MASK)
00367                 {
00368 #if FMSTR_REC_COMMON_ERR_CODES
00369             goto FMSTR_SetUpRec_exit_error;
00370 #else
00371             nResponseCode = FMSTR_STC_FLOATDISABLED;
00372             goto FMSTR_SetUpRec_exit;
00373 #endif                  
00374                 }
00375 #endif
00376                 {
00377         switch(pcm_nTrgVarSize)
00378         {
00379 #if FMSTR_CFG_BUS_WIDTH == 1U
00380         case 1: pcm_pCompareFunc = pcm_bTrgVarSigned ? FMSTR_Compare8S : FMSTR_Compare8U; break;
00381 #endif
00382         case 2: pcm_pCompareFunc = pcm_bTrgVarSigned ? FMSTR_Compare16S : FMSTR_Compare16U; break;
00383         case 4: pcm_pCompareFunc = pcm_bTrgVarSigned ? FMSTR_Compare32S : FMSTR_Compare32U; break;
00384         
00385         /* invalid trigger variable size  */
00386         default:
00387 #if FMSTR_REC_COMMON_ERR_CODES
00388             goto FMSTR_SetUpRec_exit_error;
00389 #else
00390             nResponseCode = FMSTR_STC_INVSIZE;
00391             goto FMSTR_SetUpRec_exit;
00392 #endif
00393             }
00394         }
00395     }
00396 #endif /* (FMSTR_USE_FASTREC) == 0 */
00397     
00398     /* total recorder buffer length in native sizeof units (=bytes on most platforms) */
00399     blen = (FMSTR_SIZE) (pcm_wRecTotalSmps * nRecVarsetSize / FMSTR_CFG_BUS_WIDTH);
00400 
00401     /* recorder memory available? */
00402     if(blen > FMSTR_GetRecBuffSize())
00403     {
00404 #if FMSTR_REC_COMMON_ERR_CODES
00405         goto FMSTR_SetUpRec_exit_error;
00406 #else
00407         nResponseCode = FMSTR_STC_INVSIZE;
00408         goto FMSTR_SetUpRec_exit;
00409 #endif
00410     }
00411 
00412 #if (FMSTR_USE_FASTREC) == 0
00413     /* remember the effective end of circular buffer */
00414     pcm_dwRecEndBuffPtr = pcm_nRecBuffAddr + blen;
00415 #endif /* (FMSTR_USE_FASTREC) == 0 */
00416 
00417 #if FMSTR_USE_FASTREC
00418     if(!FMSTR_SetUpFastRec())
00419     {
00420 #if FMSTR_REC_COMMON_ERR_CODES
00421         goto FMSTR_SetUpRec_exit_error;
00422 #else /* FMSTR_REC_COMMON_ERR_CODES */
00423         nResponseCode = FMSTR_STC_FASTRECERR;
00424         goto FMSTR_SetUpRec_exit;
00425 #endif /* FMSTR_REC_COMMON_ERR_CODES */
00426     }
00427 #endif /* FMSTR_USE_FASTREC */
00428 
00429     /* everything is okay    */
00430     pcm_wRecFlags.flg.bIsConfigured = 1U;
00431     nResponseCode = FMSTR_STS_OK;
00432 #if FMSTR_REC_COMMON_ERR_CODES
00433     goto FMSTR_SetUpRec_exit;
00434 FMSTR_SetUpRec_exit_error:
00435     nResponseCode = FMSTR_STC_INVSIZE;
00436 #endif
00437 FMSTR_SetUpRec_exit:
00438     return FMSTR_ConstToBuffer8(pResponse, nResponseCode);
00439 }
00440 
00441 /**************************************************************************/
00449 void FMSTR_TriggerRec(void)
00450 {
00451     if(!pcm_wRecFlags.flg.bIsStopping)
00452     {
00453         pcm_wRecFlags.flg.bIsStopping = 1U;
00454 #if (FMSTR_REC_STATIC_POSTTRIG) == 0
00455         pcm_wStoprecCountDown = pcm_wRecPostTrigger;
00456 #else
00457         pcm_wStoprecCountDown = FMSTR_REC_STATIC_POSTTRIG;
00458 #endif
00459     }
00460 }
00461 
00462 /**************************************************************************/
00476 FMSTR_BPTR FMSTR_StartRec(FMSTR_BPTR pMessageIO)
00477 {
00478      FMSTR_U8 nResponseCode;   
00479     /* must be configured */
00480     if(!pcm_wRecFlags.flg.bIsConfigured)
00481     {
00482 #if FMSTR_REC_COMMON_ERR_CODES
00483         goto FMSTR_StartRec_exit_error;
00484 #else
00485         nResponseCode = FMSTR_STC_NOTINIT;
00486         goto FMSTR_StartRec_exit;
00487 #endif
00488     }
00489         
00490     /* already running ? */
00491     if(pcm_wRecFlags.flg.bIsRunning)
00492     {
00493 #if FMSTR_REC_COMMON_ERR_CODES
00494         goto FMSTR_StartRec_exit_error;
00495 #else
00496         nResponseCode = FMSTR_STS_RECRUN;
00497         goto FMSTR_StartRec_exit;
00498 #endif
00499     }
00500 
00501 #if (FMSTR_USE_FASTREC) == 0
00502     /* initialize write pointer */
00503     pcm_dwRecWritePtr = pcm_nRecBuffAddr;
00504 
00505     /* current (first) sample index */
00506     pcm_wRecBuffStartIx = 0U;
00507 #endif /* (FMSTR_USE_FASTREC) == 0 */
00508 
00509     /* initialize time divisor */
00510 #if (FMSTR_REC_STATIC_DIVISOR) != 1
00511     pcm_wRecTimeDivCtr = 0U;
00512 #endif
00513 
00514     /* initiate virgin cycle */
00515     pcm_wRecFlags.flg.bIsStopping = 0U;          /* no trigger active */
00516     pcm_wRecFlags.flg.bTrgCrossActive = 0U;      /* waiting for threshold crossing */
00517     pcm_wRecFlags.flg.bInvirginCycle = 1U;       /* initial cycle */
00518     /* run now */
00519 
00520     /* start fast recorder */
00521 #if FMSTR_USE_FASTREC
00522     FMSTR_StartFastRec();
00523 #endif /* (MSTR_USE_FASTREC */
00524 
00525     /* run now */
00526     pcm_wRecFlags.flg.bIsRunning = 1U;           /* is running now! */
00527 
00528     nResponseCode = FMSTR_STS_OK;
00529 #if FMSTR_REC_COMMON_ERR_CODES
00530     goto FMSTR_StartRec_exit;
00531 FMSTR_StartRec_exit_error:
00532     nResponseCode = FMSTR_STC_NOTINIT;
00533 #endif
00534 
00535 FMSTR_StartRec_exit:
00536     return FMSTR_ConstToBuffer8(pMessageIO, nResponseCode);
00537 }
00538 
00539 /**************************************************************************/
00552 FMSTR_BPTR FMSTR_StopRec(FMSTR_BPTR pMessageIO)
00553 {
00554     FMSTR_U8 nResponseCode;
00555     /* must be configured */
00556     if(!pcm_wRecFlags.flg.bIsConfigured)
00557     {
00558         nResponseCode = FMSTR_STC_NOTINIT;
00559         goto FMSTR_StopRec_exit;
00560     }
00561         
00562     /* already stopped ? */
00563     if(!pcm_wRecFlags.flg.bIsRunning)
00564     {
00565         nResponseCode = FMSTR_STS_RECDONE;
00566         goto FMSTR_StopRec_exit;
00567     }
00568     
00569     /* simulate trigger */
00570     FMSTR_TriggerRec();
00571     nResponseCode = FMSTR_STS_OK;
00572     
00573 FMSTR_StopRec_exit:
00574     return FMSTR_ConstToBuffer8(pMessageIO, nResponseCode);
00575 }
00576 
00577 /**************************************************************************/
00590 FMSTR_BPTR FMSTR_GetRecStatus(FMSTR_BPTR pMessageIO)
00591 {
00592     FMSTR_U16 nResponseCode = (FMSTR_U16) (pcm_wRecFlags.flg.bIsRunning ? 
00593         FMSTR_STS_RECRUN : FMSTR_STS_RECDONE);
00594     
00595     /* must be configured */
00596     if(!pcm_wRecFlags.flg.bIsConfigured)
00597     {
00598         nResponseCode = FMSTR_STC_NOTINIT;
00599     }
00600         
00601     /* get run/stop status */
00602     return FMSTR_ConstToBuffer8(pMessageIO, (FMSTR_U8) nResponseCode);
00603 }
00604 
00605 /* now follows the recorder only routines, skip that if FastRecorder is used */
00606 #if (FMSTR_USE_FASTREC) == 0
00607 
00608 /**************************************************************************/
00616 FMSTR_SIZE FMSTR_GetRecBuffSize()
00617 {
00618 #if FMSTR_REC_OWNBUFF
00619     return pcm_wRecBuffSize;
00620 #else
00621     return (FMSTR_SIZE) FMSTR_REC_BUFF_SIZE;
00622 #endif
00623 }
00624 
00625 /**************************************************************************/
00639 FMSTR_BOOL FMSTR_IsInRecBuffer(FMSTR_ADDR dwAddr, FMSTR_SIZE8 nSize)
00640 {
00641     FMSTR_BOOL bRet = 0U;
00642     
00643     if(dwAddr >= pcm_nRecBuffAddr)
00644     {
00645         bRet = (FMSTR_BOOL)((dwAddr + nSize) <= (pcm_nRecBuffAddr + FMSTR_GetRecBuffSize()) ? FMSTR_TRUE : FMSTR_FALSE);    
00646     }
00647     
00648     return bRet;
00649 }
00650 
00651 
00652 /**************************************************************************/
00665 FMSTR_BPTR FMSTR_GetRecBuff(FMSTR_BPTR pMessageIO)
00666 {
00667          volatile FMSTR_BPTR pResponse;
00668         /* must be configured */
00669     if(!pcm_wRecFlags.flg.bIsConfigured)
00670     {
00671         return FMSTR_ConstToBuffer8(pMessageIO, FMSTR_STC_NOTINIT);
00672     }
00673     
00674     /* must be stopped */
00675     if(pcm_wRecFlags.flg.bIsRunning)
00676     {
00677         return FMSTR_ConstToBuffer8(pMessageIO, FMSTR_STC_SERVBUSY);
00678     }
00679     
00680     /* fill the return info */
00681     pResponse = FMSTR_ConstToBuffer8(pMessageIO, FMSTR_STS_OK);
00682     pResponse = FMSTR_AddressToBuffer(pResponse, pcm_nRecBuffAddr);
00683     return FMSTR_ValueToBuffer16(pResponse, pcm_wRecBuffStartIx);
00684 }
00685 
00686 /**************************************************************************/
00698 #define CMP(v,t) ((FMSTR_BOOL)(((v) < (t)) ? 0 : 1))
00699 
00700 #if FMSTR_CFG_BUS_WIDTH == 1U
00701 
00702 static FMSTR_BOOL FMSTR_Compare8S()
00703 {
00704     return CMP(FMSTR_GetS8(pcm_nTrgVarAddr), pcm_uTrgThreshold.s8);
00705 }
00706 
00707 static FMSTR_BOOL FMSTR_Compare8U()
00708 {
00709     return CMP(FMSTR_GetU8(pcm_nTrgVarAddr), pcm_uTrgThreshold.u8);
00710 }
00711 
00712 #endif
00713 
00714 static FMSTR_BOOL FMSTR_Compare16S()
00715 {
00716     return CMP(FMSTR_GetS16(pcm_nTrgVarAddr), pcm_uTrgThreshold.s16);
00717 }
00718 
00719 static FMSTR_BOOL FMSTR_Compare16U()
00720 {
00721     return CMP(FMSTR_GetU16(pcm_nTrgVarAddr), pcm_uTrgThreshold.u16);
00722 }
00723 
00724 static FMSTR_BOOL FMSTR_Compare32S()
00725 {
00726     return CMP(FMSTR_GetS32(pcm_nTrgVarAddr), pcm_uTrgThreshold.s32);
00727 }
00728 
00729 static FMSTR_BOOL FMSTR_Compare32U()
00730 {
00731     return CMP(FMSTR_GetU32(pcm_nTrgVarAddr), pcm_uTrgThreshold.u32);
00732 }
00733 
00734 #if FMSTR_REC_FLOAT_TRIG
00735 static FMSTR_BOOL FMSTR_Comparefloat()
00736 {
00737     return CMP(FMSTR_GetFloat(pcm_nTrgVarAddr), pcm_uTrgThreshold.fp);
00738 }
00739 #endif
00740 
00741 /**************************************************************************/
00751 #if defined(FMSTR_PLATFORM_56F8xxx) || defined(FMSTR_PLATFORM_56F8xx)
00752 #pragma interrupt called
00753 #endif
00754 
00755 void FMSTR_Recorder(void)
00756 {
00757     /* recorder not active */
00758     if(!pcm_wRecFlags.flg.bIsRunning)
00759     {
00760         return ;
00761     }
00762     
00763     /* do the hard work      */
00764     FMSTR_Recorder2();
00765 }
00766 
00767 /**************************************************************************/
00773 #if defined(FMSTR_PLATFORM_56F8xxx) || defined(FMSTR_PLATFORM_56F8xx)
00774 #pragma interrupt called
00775 #endif
00776 
00777 static void FMSTR_Recorder2(void)
00778 {
00779     FMSTR_SIZE8 sz;
00780     FMSTR_BOOL cmp;
00781     FMSTR_U8 i;
00782 
00783 #if (FMSTR_REC_STATIC_DIVISOR) != 1
00784     /* skip this call ? */
00785     if(pcm_wRecTimeDivCtr)
00786     {
00787         /* maybe next time... */
00788         pcm_wRecTimeDivCtr--;
00789         return;
00790     }
00791     
00792     /* re-initialize divider */
00793 #if (FMSTR_REC_STATIC_DIVISOR) == 0
00794     pcm_wRecTimeDivCtr = pcm_wRecTimeDiv;
00795 #else 
00796     pcm_wRecTimeDivCtr = FMSTR_REC_STATIC_DIVISOR;
00797 #endif /* (FMSTR_REC_STATIC_DIVISOR) == 0 */
00798 #endif /* (FMSTR_REC_STATIC_DIVISOR) != 1 */
00799 
00800     /* take snapshot of variable values */
00801     for (i=0U; i<pcm_nRecVarCount; i++)
00802     {
00803         sz = pcm_pRecVarSize[i];
00804         FMSTR_CopyMemory(pcm_dwRecWritePtr, pcm_pRecVarAddr[i], sz);
00805         sz /= FMSTR_CFG_BUS_WIDTH;
00806         pcm_dwRecWritePtr += sz;
00807     }
00808     
00809     /* another sample taken (startIx "points" after sample just taken) */
00810     /* i.e. it points to the oldest sample */
00811     pcm_wRecBuffStartIx++;
00812     
00813     /* wrap around (circular buffer) ? */
00814     if(pcm_dwRecWritePtr >= pcm_dwRecEndBuffPtr)
00815     {   
00816         pcm_dwRecWritePtr = pcm_nRecBuffAddr;
00817         pcm_wRecFlags.flg.bInvirginCycle = 0U;
00818         pcm_wRecBuffStartIx = 0U;
00819     }
00820 
00821     /* no trigger testing in virgin cycle */
00822     if(pcm_wRecFlags.flg.bInvirginCycle)
00823     {
00824         return;
00825     }
00826     
00827     /* test trigger condition if still running */
00828     if(!pcm_wRecFlags.flg.bIsStopping && pcm_pCompareFunc != NULL)
00829     {
00830         /* compare trigger threshold */
00831         cmp = pcm_pCompareFunc();
00832         
00833         /* negated logic (falling-edge) ? */
00834         if(pcm_nRecTriggerMode == 2U)
00835         {
00836             cmp = (FMSTR_BOOL) !cmp;
00837         }
00838         
00839         /* above threshold ? */
00840         if(cmp)
00841         {
00842             /* were we at least once below threshold ? */
00843             if(pcm_wRecFlags.flg.bTrgCrossActive)
00844             {
00845                 /* EDGE TRIGGER ! */
00846                 FMSTR_TriggerRec();
00847             }
00848         }
00849         else
00850         {
00851             /* we got bellow threshold, now wait for being above threshold */
00852             pcm_wRecFlags.flg.bTrgCrossActive = 1U;
00853         }
00854     }
00855     
00856     /* in stopping mode ? (note that this bit might have been set just above!) */
00857     if(pcm_wRecFlags.flg.bIsStopping)
00858     {
00859         /* count down post-trigger samples expired ? */
00860         if(!pcm_wStoprecCountDown)
00861         {
00862             /* STOP RECORDER */
00863             pcm_wRecFlags.flg.bIsRunning = 0U;
00864             return;
00865         }
00866         
00867         /* perhaps next time */
00868         pcm_wStoprecCountDown--;
00869     }
00870 }
00871 
00872 #endif /* (FMSTR_USE_FASTREC) == 0 */
00873 
00874 #else /* FMSTR_USE_RECORDER && (!FMSTR_DISABLE) */
00875 
00876 /* use void recorder API functions */
00877 void FMSTR_Recorder(void) 
00878 { 
00879 }
00880 
00881 void FMSTR_TriggerRec(void) 
00882 { 
00883 }
00884 
00885 void FMSTR_SetUpRecBuff(FMSTR_ADDR pBuffer, FMSTR_SIZE wBuffSize) 
00886 { 
00887     FMSTR_UNUSED(pBuffer);
00888     FMSTR_UNUSED(wBuffSize);
00889 }
00890 
00891 /*lint -efile(766, freemaster_protocol.h) include file is not used in this case */
00892 
00893 #endif /* FMSTR_USE_RECORDER && (!FMSTR_DISABLE) */
00894 
00895